<template>
  <div class="header">
    <div class="l-content">
      <el-button size="small" plain @click="handleCollapse">
        <!-- 图标的展示 -->
        <el-icon>
          <Menu />
        </el-icon>
      </el-button>
      <!-- 面包屑 -->
      <el-breadcrumb separator="/" class="bread">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item v-for="item in current" :to="item.path">{{ item.label }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="r-content">
      <el-dropdown>
        <span class="el-dropdown-link">
          <img class="userimg" src="https://img1.baidu.com/it/u=1191341145,3629813580&fm=253&fmt=auto&app=120&f=JPG?w=500&h=500" alt="">
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item @click="handleLoginOut">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>

</template>
<script>
import { computed } from '@vue/runtime-core'
import { onMounted } from 'vue'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
export default {
  setup() {
    const router = useRouter()
    let store = useStore()
    //左侧菜单收起功能
    let handleCollapse = () => {
      store.commit('updateIsCollapse')
    }
    // 计算属性
    const current = computed(() => {
      return store.state.currentMenu
    })

    //退出登录
    const handleLoginOut = () => {
      ElMessageBox.confirm('是否退出登录', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        center: true
      })
        .then(() => {
        
          store.commit('cleanMenu')
          store.commit('clearToken')
          router.push({
            name: 'login'
          })
            ElMessage({
            type: 'success',
            message: '退出登录成功',
            type:'success'
          })
        })
        .catch(() => {
          
        })
    }
    onMounted(() => {})
    return {
      handleCollapse,
      current,
      handleLoginOut
    }
  }
}
</script>
<style lang="less" scoped>
.header {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 5px 20px;
  align-items: center;
  background-color: #999;
  box-sizing: border-box;
  .r-content {
    .userimg {
      width: 40px;
      height: 40px;
      border-radius: 50%;
    }
  }
  .l-content {
    display: flex;
    align-items: center;
    .el-button {
      margin-right: 20px;
    }
    h3 {
      color: #fff;
    }
  }
}
.bread /deep/ span {
  color: #fff !important;
  cursor: pointer !important;
}
</style>